//
//  HYNetRequestHandle.m
//  Booking
//
//  Created by Duntech on 2018/4/19.
//  Copyright © 2018年 Duntech. All rights reserved.
//

#import "HYNetRequestHandle.h"


@implementation HYNetRequestHandle

+ (void)loginWithPhone:(NSString *)phone password:(NSString *)password complecton:(void (^)(BOOL))complection{
    NSString *url = [NSString stringWithFormat:@"%@?userName=%@&password=%@",API_UserLogin,phone,password];
    
    [[HttpManager shareHTTPManager] postDataFromUrl:url withParameter:nil showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
       
        if (baseNetModel){
           
            HYUserModel *userModel = [HYUserModel sharedInstance];
            [userModel modelSetWithDictionary:baseNetModel.result];
            [KUSERDEFAULTS setObject:phone forKey:@"phone"];
            [KUSERDEFAULTS setObject:password forKey:@"password"];
            [KUSERDEFAULTS setObject:userModel.user.id forKey:@"createBy"];
            [JRToast showWithText:[NSString stringWithFormat:@"%@ %@",NSLocalizedString(@"welcome", nil),userModel.user.realName]];
            
            //缓存用户信息,归档
            [HYPlistTools archiveObject:userModel withName:KUserModelData];
            //注册别名
            [JPUSHService setAlias:userModel.user.id completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
                
                NSLog(@"resCode : %ld, iAlias: %@, seq : %ld",(long)iResCode,iAlias,(long)seq);
            } seq:10086];

            complection(YES);
        }
        else {
            
            complection(NO);
        }
    }];
}

+ (void)getCityListComplection:(void (^)(NSArray *))complection{
    
    [[HttpManager shareHTTPManager] getDataFromUrl:API_GetCityInfo withParameter:nil showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        
        if (baseNetModel){
            
            NSArray *array = baseNetModel.result;
            complection(array);
        }
        else {
            
            complection(nil);
        }
    }];
}

+ (void)getBuildingListWithCityID:(NSString *)cityID complection:(void (^)(NSArray *))complection{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:cityID forKey:@"cityId"];
    [[HttpManager shareHTTPManager] getDataFromUrl:API_GetBuildingInfoWithCityID withParameter:param showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        
        if (baseNetModel){
            
            NSArray *array = baseNetModel.result;
            complection(array);
        }
        else {
            
            complection(nil);
        }
    }];
}

+ (void)getMeetingRoomComplection:(void (^)(NSArray *))complection{
    
    [[HttpManager shareHTTPManager] postDataFromUrl:API_GetRoomInfo withParameter:nil showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        
        if (baseNetModel){
            
            NSArray *array = baseNetModel.result;
            complection(array);
        }
        else {
            
            complection(nil);
        }
    }];
}

+(void)getAvailableMeetingRoomWithPageNo:(NSString *)pageNo pageSize:(NSString *)pageSize startTime:(NSString *)startTime endTime:(NSString *)endTime status:(NSString *)status city:(NSString *)city build:(NSString *)build floor:(NSString *)floor markName:(NSString *)markName Complection:(void (^)(NSArray *))complection{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:pageNo forKey:@"pageNo"];
    [param setValue:pageSize forKey:@"pageSize"];
    [param setValue:startTime forKey:@"startTime"];
    [param setValue:endTime forKey:@"endTime"];
    [param setValue:status forKey:@"status"];
    [param setValue:city forKey:@"city"];
    [param setValue:build forKey:@"build"];
    [param setValue:floor forKey:@"floor"];
    [param setValue:markName forKey:@"markName"];

    [[HttpManager shareHTTPManager] getDataFromUrl:API_GetAvailableMeetingRoomList withParameter:param showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        if (baseNetModel){
            
            NSArray *listArray = baseNetModel.result;
            complection(listArray);
        }
        else {
            
            complection(nil);
        }
    }];
}

+ (void)bookingMeetingRoomWithCreateBy:(NSString *)createBy attendees:(NSString *)attendees dataSource:(NSString *)dataSource currdate:(NSString *)currdate startDayTime:(NSString *)startDayTime endDayTime:(NSString *)endDayTime markName:(NSString *)markName meetingroomId:(NSString *)meetingroomId organizationman:(NSString *)organizationman outattendees:(NSString *)outattendees remark:(NSString *)remark Complection:(void (^)(BOOL))complection{
    
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:createBy forKey:@"createBy"];
    [param setValue:attendees forKey:@"attendees"];
    [param setValue:dataSource forKey:@"dataSource"];
    [param setValue:currdate forKey:@"currdate"];
    [param setValue:startDayTime forKey:@"startDayTime"];
    [param setValue:endDayTime forKey:@"endDayTime"];
    [param setValue:markName forKey:@"markName"];
    [param setValue:meetingroomId forKey:@"meetingroomId"];
    [param setValue:organizationman forKey:@"organizationman"];
    [param setValue:outattendees forKey:@"outattendees"];
    [param setValue:remark forKey:@"remark"];
    
    [[HttpManager shareHTTPManager] postDataFromUrl:API_BookingMeetingRoom withParameter:param showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        
        if (baseNetModel){
            
            complection(YES);
        }
        else {
            
            [JRToast showWithText:baseNetModel.msg duration:2];
            complection(NO);
        }
    }];
}

+ (void)getMyScheduleRoomWithCreateBy:(NSString *)createBy status:(NSString *)status city:(NSString *)city build:(NSString *)build floor:(NSString *)floor startTime:(NSString *)startTime endTime:(NSString *)endTime markName:(NSString *)markName meetingroomId:(NSString *)meetingroomId Complection:(void (^)(NSArray *))complection{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:nil forKey:@"pageNo"];
    [param setValue:nil forKey:@"pageSize"];
    [param setValue:createBy forKey:@"createBy"];
    [param setValue:status forKey:@"signStatus"];
    [param setValue:city forKey:@"city"];
    [param setValue:build forKey:@"build"];
    [param setValue:floor forKey:@"floor"];
    [param setValue:startTime forKey:@"startTime"];
    [param setValue:endTime forKey:@"endTime"];
    [param setValue:markName forKey:@"markName"];
    [param setValue:meetingroomId forKey:@"meetingroomId"];
    
    [[HttpManager shareHTTPManager] getDataFromUrl:API_GetMySchedule withParameter:param showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        
        if (baseNetModel){
            
            NSArray *listArray = baseNetModel.result;
            complection(listArray);
        }
        else {
            
            complection(nil);
        }
    }];
}

+ (void)getMyScheduleSeatWithCreateBy:(NSString *)createBy status:(NSString *)status startTime:(NSString *)startTime endTime:(NSString *)endTime stationId:(NSString *)stationId Complection:(void (^)(NSArray *))complection{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:nil forKey:@"pageNo"];
    [param setValue:nil forKey:@"pageSize"];
    [param setValue:startTime forKey:@"startTime"];
    [param setValue:endTime forKey:@"endTime"];
    [param setValue:status forKey:@"status"];
    [param setValue:createBy forKey:@"createBy"];
    [param setValue:stationId forKey:@"stationId"];
    
    [[HttpManager shareHTTPManager] getDataFromUrl:API_GetMyScheduleSeat withParameter:param showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        
        if (baseNetModel){
            
            NSArray *listArray = baseNetModel.result;
            complection(listArray);
        }
        else {
            
            complection(nil);
        }
    }];
}

+ (void)getAvailableSeatListWithPageNo:(NSString *)pageNo pageSize:(NSString *)pageSize startTime:(NSString *)startTime endTime:(NSString *)endTime status:(NSString *)status cityId:(NSString *)cityId buildId:(NSString *)buildId floorId:(NSString *)floorId Complection:(void (^)(NSArray *))complection{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:pageNo forKey:@"pageNo"];
    [param setValue:pageSize forKey:@"pageSize"];
    [param setValue:startTime forKey:@"startTime"];
    [param setValue:endTime forKey:@"endTime"];
    [param setValue:status forKey:@"status"];
    [param setValue:cityId forKey:@"cityId"];
    [param setValue:buildId forKey:@"buildId"];
    [param setValue:floorId forKey:@"floorId"];
    [[HttpManager shareHTTPManager] getDataFromUrl:API_GetAvailableSeatList withParameter:param showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        
        if (baseNetModel){
            
            NSArray *listArray = baseNetModel.result;
            complection(listArray);
        }
        else {
            
            complection(nil);
        }
    }];
}

+ (void)bookingSeatWithSeatID:(NSString *)seatID currdate:(NSString *)currdate startDayTime:(NSString *)startDayTime endDayTime:(NSString *)endDayTime remark:(NSString *)remark Complection:(void (^)(BOOL))complection{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:[HYUserModel sharedInstance].user.id forKey:@"createBy"];
    [param setValue:seatID forKey:@"stationId"];
    [param setValue:startDayTime forKey:@"startDayTime"];
    [param setValue:endDayTime forKey:@"endDayTime"];
    [param setValue:currdate forKey:@"currdate"];
    [param setValue:remark forKey:@"remark"];
    
    [[HttpManager shareHTTPManager] postDataFromUrl:API_BookingSeat withParameter:param showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        
        if (baseNetModel){
            
            complection(YES);
        }
        else {
            complection(NO);
        }
    }];
}

+ (void)getMeetingInviterListWithPageNo:(NSString *)pageNo pageSize:(NSString *)pageSize Complection:(void (^)(NSArray *))complection{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:pageNo forKey:@"pageNo"];
    [param setValue:pageSize forKey:@"pageSize"];
    [param setValue:@"" forKey:@"loginName"];
    [param setValue:@"" forKey:@"realName"];
    [param setValue:@"" forKey:@"phone"];
    
    [[HttpManager shareHTTPManager] getDataFromUrl:API_GetMeetingInviterList withParameter:param showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        if (baseNetModel){
            
            NSArray *listArray = baseNetModel.result;
            complection(listArray);
        }
        else {
            
            complection(nil);
        }
    }];
}

+ (void)cancelMyBookingRoomWithMeetingID:(NSString *)meetingID complection:(void (^)(BOOL))complection{
    
    NSString *url = [NSString stringWithFormat:@"%@/%@",API_CancelMyBookingRoomWithID,meetingID];
    [[HttpManager shareHTTPManager] deleteDataFromUrl:url withParameter:nil showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        
        if (baseNetModel){
            
            complection(YES);
        }
        else {
            complection(NO);
        }
    }];
}

+ (void)cancelMyBookingSeatWithSeatID:(NSString *)seatID complection:(void (^)(BOOL))complection{
    NSString *url = [NSString stringWithFormat:@"%@/%@",API_CancelMyBookingSeatWithID,seatID];
    [[HttpManager shareHTTPManager] deleteDataFromUrl:url withParameter:nil showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        
        if (baseNetModel){
            
            complection(YES);
        }
        else {
            complection(NO);
        }
    }];
}

+ (void)getRoomDetailWithMeetingID:(NSString *)meetingID complection:(void (^)(HYBaseNetworkModel *))complection{
    NSString *url = [NSString stringWithFormat:@"%@/%@",API_GetRoomDetailWithMeetingID,meetingID];
    [[HttpManager shareHTTPManager] getDataFromUrl:url withParameter:nil showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        
        if (baseNetModel){
            
            complection(baseNetModel);
        }
        else {
            complection(nil);
        }
    }];
}

+(void)getSeatDetailWithSeatID:(NSString *)seatID complection:(void (^)(HYBaseNetworkModel *))complection{
    NSString *url = [NSString stringWithFormat:@"%@/%@",API_GetSeatDetailInfo,seatID];
    [[HttpManager shareHTTPManager] getDataFromUrl:url withParameter:nil showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        
        if (baseNetModel){
            
            complection(baseNetModel);
        }
        else {
            complection(nil);
        }
    }];
}

+ (void)searchMeetingInviterListWithKeywords:(NSString *)keywords complection:(void (^)(NSArray *))complection{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:keywords forKey:@"keyword"];
    
    [[HttpManager shareHTTPManager] postDataFromUrl:API_GetMeetingInviterWithKeywords withParameter:param showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        
        if (baseNetModel){
            
            complection(baseNetModel.result);
        }
        else {
            complection(nil);
        }
    }];
}

+ (void)signInWithRoomID:(NSString *)roomID complection:(void (^)(BOOL))complection{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:[HYUserModel sharedInstance].user.id forKey:@"createBy"];
    [param setValue:roomID forKey:@"roomid"];
    
    [[HttpManager shareHTTPManager] putDataFromUrl:API_SignByUserID withParameter:param showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        if (baseNetModel){
            
            complection(YES);
        }
        else {
            complection(NO);
        }
    }];
}

+ (void)signInIPadWithRoomID:(NSString *)roomID registerId:(NSString *)registerId complection:(void (^)(BOOL))complection{
    NSString *url = [NSString stringWithFormat:@"%@?createBy=%@&roomid=%@&regid=%@",API_SignIPadByUserID,[KUSERDEFAULTS objectForKey:@"createBy"],roomID,registerId];
    
    [[HttpManager shareHTTPManager] postDataFromUrl:url withParameter:nil showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        if (baseNetModel){
            
            complection(YES);
        }
        else {
            complection(NO);
        }
    }];
}

+ (void)loginIpadWithRegisterId:(NSString *)registerId complecton:(void (^)(BOOL))complection{
    NSString *url = [NSString stringWithFormat:@"%@?userName=%@&password=%@&registerId=%@",API_UserLoginIPad,KAccountPhone,KAccountPassword,registerId];
    
    [[HttpManager shareHTTPManager] postDataFromUrl:url withParameter:nil showHUDView:KEYWINDOW success:^(HYBaseNetworkModel *baseNetModel) {
        if (baseNetModel){
            
            complection(YES);
        }
        else {
            
            complection(NO);
        }
    }];
}

@end
